import { COUPON_OFFER_TYPE, COUPON_SCOPE_TYPE } from '@constants/market';
import { formatDate } from '@common/format';
const DATE_FORMAT = 'YYYY.MM.DD';

/**
 * 获取订单的可用优惠券
 * @param {Object} orderInfo 订单信息
 * @param {ArrayList} couponList 用户优惠券列表
 */
export const dealOrderCoupon = (orderInfo, couponList) => {

};


/**
 * 处理优惠券信息为可用信息
 * @param {Object} couponInfo 优惠券信息
 */
export const dealCouponItem = (couponInfo = {}) => {
    const { id, coupon_id, sn, name, price, offer_type, quota, scope, item_confs = [], begined, ended } = couponInfo;
    const isDiscount = offer_type == COUPON_OFFER_TYPE.discount; // 是否是折扣
    let valueTip = '';
    switch(offer_type) {
    case COUPON_OFFER_TYPE.discount:
        valueTip = quota > 0 ? `满${quota / 100}可用` : '无门槛';
        break;
    case COUPON_OFFER_TYPE.limit:
        valueTip = quota > 0 ? `满${quota / 100}可用` : '无门槛';
        break;
    case COUPON_OFFER_TYPE.cut:
        valueTip = quota > 0 ? `满${quota / 100}可用` : '无门槛';
        break;
    case COUPON_OFFER_TYPE.quotaCut:
        valueTip = quota > 0 ? `满${quota / 100}减${price / 100}` : '无门槛';
        break;
    }
    let isAll = false;
    let include = [];
    let exclude = [];
    switch(scope) {
    case COUPON_SCOPE_TYPE.none:
    case COUPON_SCOPE_TYPE.unlimited:
        isAll = true;
        break;
    case COUPON_SCOPE_TYPE.includeItems:
        include = [...item_confs.map(item => item.id)];
        break;
    case COUPON_SCOPE_TYPE.excludeItems:
        exclude = [...item_confs.map(item => item.id)];
        break;
    }
    return {
        id, // id
        couponId: coupon_id, // 优惠券id
        sn, // sn
        name, // 名字
        value: price, // 优惠金额或优惠折扣
        valueTip, // 优惠提示
        isDiscount, // 是否是折扣
        isAll, // 是否是全部可用
        include, // 包含
        exclude, // 排除
        useDateString: `${formatDate(begined, DATE_FORMAT)} 至 ${formatDate(ended, DATE_FORMAT)}`, // 可用时间
    };
};
